//
//  QcodeLoginViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/8.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "QcodeLoginViewController.h"

@interface QcodeLoginViewController ()

@end

@implementation QcodeLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"扫码登录";
    self.myScrollView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    [self.view addSubview:self.myScrollView];
    [self createUI];
}

-(void)createUI{
    GLGWImageView * p_image = [[GLGWImageView alloc] initWithFrame:CGRectMake((KScreenWidth-kWidthProportion_In_iPhoneTriploid(132))/2, kHeightProportion_In_iPhoneTriploid(173), kWidthProportion_In_iPhoneTriploid(132), kHeightProportion_In_iPhoneTriploid(103)) imageName:@"icon_diannao" inSuperView:self.myScrollView];
    //
    GLGWLabel * glgwLabel = [[GLGWLabel alloc] initWithFrame:CGRectMake(0, kY_With_View(p_image, 30), KScreenWidth, kHeightProportion_In_iPhoneTriploid(22)) theFont:SYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self.myScrollView];
    glgwLabel.text = @"钢来钢往官网登录确认";
    glgwLabel.textAlignment = NSTextAlignmentCenter;
    //
    GLGWLabel * sever_Label = [[GLGWLabel alloc] initWithFrame:CGRectMake(0, kY_With_View(glgwLabel, 12), KScreenWidth, kHeightProportion_In_iPhoneTriploid(20)) theFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.myScrollView];
    sever_Label.textAlignment = NSTextAlignmentCenter;
    sever_Label.text = @"为保障账户安全，请确认是本人操作";
    //
    CGFloat leftWidth = (KScreenWidth - kWidthProportion_In_iPhoneTriploid(200))/2;
    NSArray * titArr = @[@"登录",@"取消"];
    for (int i=0; i<2; i++) {
        GLGWButton * but = [[GLGWButton alloc] initWithFrame:CGRectMake(leftWidth, kY_With_View(sever_Label, 80) + kHeightProportion_In_iPhoneTriploid(44)*i + kHeightProportion_In_iPhoneTriploid(5)*i, kWidthProportion_In_iPhoneTriploid(200), kHeightProportion_In_iPhoneTriploid(44)) hTitle:titArr[i] titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor whiteColor] theCornerRadius:kHeightProportion_In_iPhoneTriploid(22) backgroundColr:kColor_Rule_Yellow inSuperView:self.myScrollView];
        but.tag = 100+i;
        //
        if (i==1) {
            but.backgroundColor = [UIColor clearColor];
            [but setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        }
        [but addTarget:self action:@selector(butAction:) forControlEvents:UIControlEventTouchUpInside];
        self.myScrollView.contentSize = CGSizeMake(KScreenWidth, kY_With_View(but, 30));
    }
    
}

-(void)butAction:(GLGWButton *)sender{
    if (sender.tag == 100) {
        [self requestQcodeLogin];
    }else{
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

-(void)requestQcodeLogin{
    [GLGWRequestTool POST:[NSString stringWithFormat:@"%@%@",kApiPrefix,kGLGWauth] lodingView:nil lodingTextString:@"" isLoding:YES parameters:@{@"uid":koString(_tokenStr),@"userId":koString(self.userId)} success:^(id  _Nullable response) {
        BaseModel * b_model = [BaseModel yy_modelWithJSON:response];
        if (b_model.code == 0) {
            [GLGWProgressHUD showNotice:b_model.data view:nil];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else{
            [GLGWProgressHUD showNotice:@"登录失败" view:nil];
        }
    } failure:^(NSError * _Nullable error) {
    
    }];
}

@end
